﻿@model List<FC.Data.ViewModels.Contests.ProblemCollection>

@{
    ViewBag.Title = "Contests";
    Layout = "~/Views/Shared/_ManagerLayout.cshtml";
}

@section Buttons{
    <a class="btn btn-success" href="~/Manager/EditContest">添加试题集</a>
<a class="btn btn-warning" href="~/Manager/Import">批量导入</a>
<a class="btn btn-info" href="~/Manager/Export">全部导出</a>
}

<table class="table table-bordered table-hover">
    <tr>
        <th style="width: 120px;">
            编号
        </th>
        <th>
            名称
        </th>
        <th style="width: 100px;">
            状态
        </th>
        <th style="width: 150px;">
            操作
        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                <a href="~/Manager/Problems/@item.Code">
                    @Html.DisplayFor(modelItem => item.Code)
                </a>
            </td>
            <td>
                <a href="~/Manager/Problems/@item.Code">
                    @Html.DisplayFor(modelItem => item.Name)
                </a>
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.State)
            </td>
            <td>
                <a class="btn btn-info" href="~/Manager/EditContest/@item.Code" style="height:24px;padding:2px 10px">编辑</a>
                <a class="btn btn-danger" href="#" onclick="Delete('@item.Code')" style="height:24px;padding:2px 10px">删除</a>
            </td>
        </tr>
    }
</table>

@section Script{
    <script>
        function Delete(code) {
            if (confirm("确定要删除该习题集吗？")) {
                $.ajax({
                    type: "post",
                    url: "/Manager/DeleteContest/" + code,
                    success: function (result) {
                        if (result.state == "ok") {
                            alert("删除成功");
                            window.location = "/Manager/Contests";
                        }
                        else {
                            alert(result.message);
                        }
                    }
                });
            }
        }
    </script>    
}